<?php
date_default_timezone_set("Asia/Shanghai");
//exit;
include 'functions.php';
//$conn=mysql_connect("localhost","root","");
include 'db.php'; //数据库连接
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";

$start = isset($_POST['start']) ? trim($_POST['start']) : date('Y-m-d');
$date_start = strtotime($start); 
$end = isset($_POST['end']) ? trim($_POST['end']) : date('Y-m-d',$date_start+3600*24);
$date_end = strtotime($end);	

//今天是第一次投的
//$sql = "select sum(account) as money from ych_yjb_tender 
//where add_time>=$date_start and add_time<$date_end 
//and user_id not in(select distinct user_id from ych_yjb_tender where add_time<$date_start)";

//易居宝投资总额
$sql = "select sum(account) as money from ych_yjb_tender where add_time>=$date_start and add_time<$date_end";
$rs = db_fetch_array($sql,$conn);
$yjb_money = $rs['money'] ? $rs['money'] : 0;

////易居宝成交比数
//$sql = "select count(id) as total from ych_yjb_tender where add_time>=$date_start and add_time<$date_end";
//$rs = db_fetch_array($sql,$conn);
//$yjb_tenders = $rs['total'] ? $rs['total'] : 0;

//易居宝投资人数
$sql = "select count(distinct user_id) as total from ych_yjb_tender where add_time>=$date_start and add_time<$date_end";
$rs = db_fetch_array($sql,$conn);
$yjb_users = $rs['total'] ? $rs['total'] : 0;


//流转标投资总额
$sql = "select sum(p1.account) as money from ych_borrow_tender as p1 
	left join ych_borrow as p2 on p1.borrow_id=p2.id 
	where p2.ftype=4 and p2.fstatus in(1,3) and p1.add_time>=$date_start and p1.add_time<$date_end";
$rs = db_fetch_array($sql,$conn);
$lzb_money = $rs['money'] ? $rs['money'] : 0;

//流转标投资人数
$sql = "select count(distinct p1.user_id) as total from ych_borrow_tender as p1 
	left join ych_borrow as p2 on p1.borrow_id=p2.id 
	where p2.ftype=4 and p2.fstatus in(1,3) and p1.add_time>=$date_start and p1.add_time<$date_end";
$rs = db_fetch_array($sql,$conn);
$lzb_users = $rs['total'] ? $rs['total'] : 0;

//注册人数
$sql = "select count(user_id) as total from ych_user where add_time>=$date_start and add_time<$date_end";
$rs = db_fetch_array($sql,$conn);
$reg_users = $rs['total'] ? $rs['total'] : 0;

//注册且实名人数
$sql = "select count(user_id) as total from ych_user where real_status=1 and add_time>=$date_start and add_time<$date_end";
$rs = db_fetch_array($sql,$conn);
$reg_realname = $rs['total'] ? $rs['total'] : 0;

//当天才开始投易居宝的用户投标情况
$sql = "select p1.*,p2.username,p2.add_time as reg_time from ych_yjb_tender 
	left join ych_user as p2 on p1.user_id=p2.user_id 
	where p1.add_time>=$date_start and p1.add_time<$date_end 
	and p1.user_id not in(select distinct user_id from ych_yjb_tender where add_time<$date_start)
	and p1.user_id not in(select distinct user_id from ych_borrow_tender where add_time<$date_start)";
$yjb_list = db_fetch_arrays($sql,$conn);

//当天才开始投流转标的用户投标情况
$sql = "select p1.*,p2.username,p2.add_time as reg_time,p3.time_limit from ych_borrow_tender as p1
	left join ych_user as p2 on p1.user_id=p2.user_id
	left join ych_borrow as p3 on p1.borrow_id=p3.id
	where p3.ftype=4 and p3.fstatus in(1,3) and p1.add_time>=$date_start and p1.add_time<$date_end 
	and p1.user_id not in(select distinct user_id from ych_borrow_tender where add_time<$date_start)
	and p1.user_id not in(select distinct user_id from ych_yjb_tender where add_time<$date_start)";
$lzb_list = db_fetch_arrays($sql,$conn);

?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
table{border-right:1px solid gray;border-bottom:1px solid gray}
table td{border-left:1px solid gray;border-top:1px solid gray}
</style>
<form action="" method="post">
时间：<input type="text" name="start" value="<?php echo $start;?>"> 至 <input type="text" name="end" value="<?php echo $end;?>">时间格式(2013-01-01)
<input type="submit" value="查询">
</form>
<hr>
<?php echo date('Y-m-d',$date_start);?>
<table border="0" cellspacing="0" cellpadding="0" width="80%">
	<tr>
		<td>注册人数</td>
		<td>注册且实名人数</td>
		<td>易居宝成交金额</td>
		<td>易居宝成交人数</td>
		<td>流转标成交金额</td>
		<td>流转标成交人数</td>
	</tr>
	<tr>
		<td><?php echo $reg_users;?></td>
		<td><?php echo $reg_realname;?></td>
		<td><?php echo $yjb_money;?></td>
		<td><?php echo $yjb_users;?></td>
		<td><?php echo $lzb_money;?></td>
		<td><?php echo $lzb_users;?></td>
	</tr>
</table>
<hr>
（当天第一次投标用户）易居宝投资明细
<table>
  <tr>
    <td>用户名</td>
    <td>投标金额</td>
    <td>投标期限</td>
    <td>投标时间</td>
    <td>注册时间</td>
  </tr>
  <?php foreach ($yjb_list as $val){?>
  <tr>
    <td><?php echo $val['username'];?></td>
    <td><?php echo $val['account'];?></td>
    <td><?php echo $val['time_limit_day'];?>天</td>
    <td><?php echo date('Y-m-d H:i:s',$val['add_time']);?></td>
    <td><?php echo date('Y-m-d H:i:s',$val['reg_time']);?></td>
  </tr>
  <?php }?>
</table>
<hr>
（当天第一次投标用户）流转标投资明细
<table>
  <tr>
    <td>用户名</td>
    <td>投标金额</td>
    <td>投标期限</td>
    <td>投标时间</td>
    <td>注册时间</td>
  </tr>
  <?php foreach ($lzb_list as $val){?>
  <tr>
    <td><?php echo $val['username'];?></td>
    <td><?php echo $val['account'];?></td>
    <td><?php echo $val['time_limit'];?>个月</td>
    <td><?php echo date('Y-m-d H:i:s',$val['add_time']);?></td>
    <td><?php echo date('Y-m-d H:i:s',$val['reg_time']);?></td>
  </tr>
  <?php }?>
</table>


